<template>
    <view class="content">
        <van-nav-bar :title="scrolling ? navBarTitle : ''" left-arrow @click-left="onClickLeft" class="navBar"> </van-nav-bar>
        <scroll-view class="scroll-content" scroll-y :lower-threshold="80" @scroll="scrollPage" id="scroller"
        show-scrollbar="false" @scrolltolower="scrolltolower">
        <!-- <view class="page"> -->
            <view class="pageTitle">{{navBarTitle }} <span>近三个月</span> </view>
            <view class="search-container">
                <van-search :value="searchValue" placeholder="请输入手机号/运单号/取件码" @search="onSearch" @cancel="onCancel"
                    @change="onChange" @clear="clearSearchData" shape="round" :use-action-slot="true" custom-class="search-style" 
                    background="transparent" >
                    <view slot="action" @tap="onClick">搜索</view>
                </van-search>
            </view>
            <view class="tabsBox">
                <view class="filter_option item_option"
                    :class="{ 'filter_option_selected item_option_selected': current === val }"
                    v-for="(item, val) in tabsList" :key="index" @click="selectFilter(val, $event, item.tabsName)">
                    {{ item.tabsName }}</view>
            </view>
            <!-- display: (current === 0 || current === 3) && expressList && expressList.length > 0 ? '' : 'none' -->
            <!-- (current==0 ||  current==3) &&expressList && expressList.length >0  -->
             <!-- <template v-if="showTopTips"> -->
            <view class="searchStatistic" :class="{'sticky': isSticky}" :style="{ top: isSticky ? navBarHeight + 'px' : 'auto', }" >近3个月查询到 <span v-if="current ==0 ">{{phoneCount}}个不同{{ '手机号'}}</span> <span v-if="current ==3 ">{{nameCount}}个同名</span> ，未出库<span> {{allNonOutboundCount}}</span>个包裹。 </view>
            <!-- </template> -->
            <view class="expressListBox" v-if="(expressList && expressList.length > 0) || (resultList && resultList.length > 0)">
                <view style="padding: 0 48rpx;" v-if="(current==0 || current==3) && expressList && expressList.length > 0 &&showExpressList ">
                    <van-list >
                        <block v-for="(i, j) in expressList" :key="j">
                            <view class="expressList" @tap="toInfo(i)">
                                <view  class="expressList_left">
                                    <view>{{i.phone}}</view> <view class="name  ml40">{{i.name}}</view>
                                </view>
                                <view style="display: flex;align-items: center;" class="expressList_right">
                                    <view class="">未出库 <span class="num">{{i.notOutboundCount}}</span></view>
                                    <van-icon name="arrow"/>
                                </view>
                            </view>
                        </block>
                    </van-list>
                </view>
                <searchList :resultList="resultList" @checkbox-change="handleCheckboxChange"
                    @handlechecked="handlechecked" :check-all="checkAll" @submitSinglePackage="submitSinglePackage"
                    @cancelStockOut = "cancelStockOut"  @showMoreAction="showMoreAction" :type="'search'" :activiteTab="current" :showBottomList="!showExpressList"></searchList>
            </view>
            <view class="noPackagewrapper" v-else>
                <van-empty class="custom-image"
                    image="https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/emptyPackage.png"
                    description="暂无包裹信息" />
            </view>
            <!-- </scroll-view> -->
        <!-- </view> -->
        </scroll-view>

        <template v-if="showBottomBtn">
            <view class="nav_box">
                <van-submit-bar price="" button-text="一键出库" button-type="warning" @submit="allTakeOut" :disabled="isSubmiting" :class="{ 'is-submiting': isSubmiting }">
                    <view style="display: flex; align-items: center;" class="delete">
                        <van-checkbox checked-color="#FF6203" v-model="checkAll" :label-disabled="false"
                            @click="onChangeItem('多选')" @change="handleCheckAll" use-icon-slot>
                            <image @change="handleCheckAll" slot="icon" class="checked-img"
                                :src="checkAll ? activeIcon : inactiveIcon" />
                        </van-checkbox>
                        <view class="selectedNum" @click="onChangeItem('多选')">已选（{{ selectedRowKeys.length }}）</view>
                    </view>
                </van-submit-bar>
            </view>
        </template>
        <van-toast id="van-toast" />
        <van-dialog id="van-dialog" confirm-button-color='#ff6203' />
        <moreActionsPopup :showPopup="showActSheet" :packageInfo="packageInfo" @onCloseActions="onCloseActions"  @onConfirmCancel="onConfirmCancel" :action="moreActions"></moreActionsPopup>
    </view>
</template>
<script>
import Toast from '@/wxcomponents/vant/toast/toast'
import Dialog from '@/wxcomponents/vant/dialog/dialog'

import searchList from '@/mycomponents/merchant/searchList.vue'
import moreActionsPopup from '@/mycomponents/merchant/moreActionsPopup.vue'
import {getSelfPickupSearchApi,getSelfPickupDrillByPhoneApi,handleInboundApi,handleOutboundApi,cancelSelfPickupApi} from '@/api/merchant.js'
export default {
    components:{
        searchList,
        moreActionsPopup
    },
    props: {
        show: {
            type: Boolean,
            default: () => false
        },
        popupParams: {
            type: Object,
            default: () => ({})
        }
    },
    data () {
        return {
            navBarTitle:'快件查询',
            searchPlaceholder: 'Enter tracking number',
            searchButton: 'Search',
            tabsList: [
                {
                    key: '0',
                    tabsName: '手机号'
                },
                {
                    key: '1',
                    tabsName: '运单号'
                },
                {
                    key: '2',
                    tabsName: '取件码'
                },
                {
                    key: '3',
                    tabsName: '姓名'
                },
            ],
            current:0, //当前选中的tab
            status: {
                notOutbound: 'Not Outbound',
                outbound: 'Outbound'
            },
            searchValue: '',
            tabActive: 0,
            showExpressList:true, //是否显示快递列表
            showBottomBtn:false, //是否显示底部按钮
            expressList: [
                // { phone: '198****1000', name: '刘*而', status: 1, notOutboundCount: 1  },
                // { phone: '185****1000', name: '张桐二', status: 1, notOutboundCount: 1   },
                // { phone: '15232651000', name: '孙*俪', status: 0, notOutboundCount: 1   },
                // { phone: '18546781000', name: '刘*娥', status: 0, notOutboundCount: 1   }
            ],
            phoneCount:0, //同名字不同手机数量
            nameCount:0, //同手机不同名字数量
            allNonOutboundCount:0, //未出库包裹数量
            resultList:[
                // {
                //     wayBillNo:'1234567890124',
                //     pickupCode:'2205',
                //     status:'hasOut',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     name:"张伟",
                //     phone:"18546781000",
                //     mobile:"18546781000",
                //     notOutboundCount:1,
                // },
                // {
                //     wayBillNo:'1234567890123',
                //     pickupCode:'2203',
                //     status:'awaitIn',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     name:"张伟",
                //     phone:"18546781000",
                //     mobile:"18546781000",
                //     notOutboundCount:1,
                // },
                // {
                //     wayBillNo:'1234567890125',
                //     pickupCode:'2205',
                //     status:'hasIn',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     name:"张伟",
                //     phone:"18546781000",
                //     mobile:"18546781000",
                //     notOutboundCount:1,
                // },
                // {
                //     wayBillNo:'1234567890126',
                //     pickupCode:'2203',
                //     status:'returnAwaitIn',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     name:"张伟",
                //     phone:"18546781000",
                //     mobile:"18546781000",
                //     notOutboundCount:1,
                // },
                // {
                //     wayBillNo:'1234567890127',
                //     pickupCode:'2205',
                //     status:'returnAwaitOut',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     name:"张伟",
                //     phone:"18546781000",
                //     mobile:"18546781000",
                //     notOutboundCount:1,
                // },
                // {
                //     wayBillNo:'1234567890128',
                //     pickupCode:'2203',
                //     status:'hasOut',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     name:"张伟",
                //     phone:"18546781000",
                //     mobile:"18546781000",
                //     notOutboundCount:1,
                // }
            ],
            singleList:[], //单个包裹运单号列表
            checkAll: false, // 全选状态
            selectedRowKeys: [], // 已选择的数据的id
            selectedRows: [], // 已选择的数据
            checked: [],
            inactiveIcon:
                'https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/notChecked1126.png',
            activeIcon:
                'https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/goodsChecked1126.png',
            disabledIcon: 'https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/disabledIcon.png',
            isShowBlue: false,
            showActSheet: false, // 控制动作面板的显示
            moreActions: [
                { name: '转上门', color: '#ff4949' },
                { name: '取消入库', color: '#1989fa' },
            ],
            isSticky: false,
            stickyTop: 0,
            navBarHeight:0, // 导航栏高度
            scrolling: false, // 滚动状态
            statusMap:{
                1: "待入库",
                2: "已入库",
                3: "已出库",
                4:"异常",
                5: "待退货入库",
                6: "退货待出库",
                7: "当前库存",
                8: "滞留"
            },
            showTopTips: false, // 控制顶部搜索结果提示的显示
            packageInfo:undefined,
            currentHandlePhone:'',
            isSubmiting: false // 控制提交状态
        }
    },

    computed: {
        shouldShowTopTips() {
            return (this.current === 0 || this.current === 3) && this.expressList && this.expressList.length > 0;
        },
        // 过滤出可点击的数据 
        newResultList(){  
            return this.resultList.filter(item => item.status==2)
        },
        // 选出不可点击的数据
        disabledResultList(){  
            return this.resultList.filter(item => item.status!==2)
        },
        filteredArray() {
            return this.selectedRows.filter(item => this.disabledResultList.indexOf(item) === -1);
        }

    },

    watch:{
        resultList: {
            immediate: true,
            handler(val) {
                console.log(val)
                if (!val || val.length === 0) {
                    this.checkAll = false;
                    this.showBottomBtn = false
                    return false
                }else{
                    this.showBottomBtn = true
                }
                // var i = 0
                // this.resultList.forEach(item => {
                //     if (item.isChecked === true) {
                //         i++
                //     }
                //     this.checkAll = i === this.resultList.length
                // })
            },
            deep: true
        },
        newResultList: {
            handler(val) {
                console.log(val)
                if (val.length === 0) {
                    this.checkAll = false;
                    return;
                }
                var i = 0
                this.newResultList.forEach(item => {
                    if (item.isChecked === true) {
                       i++
                    }
                    console.log(this.newResultList, 'newResultList')
                    this.checkAll = i === this.newResultList.length
        
                })
            },
            deep: true
        },
        checked: {
            handler (val) {
                console.log(val, 'newName')
            }
        },
        selectedRowKeys: {
            handler (val) {
                console.log(val, 'selectedRowKeys')
            }
        },
        selectedRows: {
            handler (val) {
                console.log(val, 'selectedRows')
            }
        },
        expressList: {
            immediate: true,
            handler(newVal) {
                console.log('expressList changed:', newVal);
                console.log('v-show condition:', (this.current === 0 || this.current === 3) && newVal.length > 0);
                this.getHeights();
            }
        },
        current: {
            immediate: true,
            handler(newVal) {
                console.log('current changed:', newVal);
                console.log('v-show condition:', (newVal === 0 || newVal === 3) && this.expressList.length > 0);
                this.getHeights();
            }
        },
        shouldShowTopTips: {
            immediate: true,
            handler(newVal) {
                console.log('shouldShowTopTips changed:', newVal);
                this.showTopTips = newVal;
            },
            deep: true
        },

    },
    onLoad () {

    },
    onReady () {
        // this.resultList.forEach(ele => {
        //     this.$set(ele, 'isChecked', false)
        //     ele.statusText = this.getStatusText(ele.status)
        // });

        this.getHeights();
        // const query = uni.createSelectorQuery().in(this);
        // query.select('.navBar').boundingClientRect(res => {
        //     this.navBarHeight = res.height  // 获取导航栏实际高度
        // }).exec()
        // query.select('.searchStatistic').boundingClientRect(res => {
        //     this.stickyTop = res?.top
        // }).exec()
     },

    methods: {
        // 滑动
        scrollPage(e) {
            const scrollTop = e.detail.scrollTop
            this.isSticky = scrollTop >= (this.stickyTop - this.navBarHeight)
            console.log(e.detail.scrollTop,this.stickyTop - this.navBarHeight,this.isSticky)
            if (e.detail.scrollTop > 25 && !this.scrolling) {
                this.scrolling = true
            } else if ((e.detail.scrollTop <= 25 && this.scrolling) || (e.detail.scrollTop <= 25 && !this.scrolling)) {
                this.scrolling = false
            }
        },
        scrollPageList(){
            console.log(e.detail.scrollTop, this.scrolling)
            if (e.detail.scrollTop > 25 && !this.scrolling) {
                this.scrolling = true
            } else if ((e.detail.scrollTop <= 25 && this.scrolling) || (e.detail.scrollTop <= 25 && !this.scrolling)) {
                this.scrolling = false
            }
        },
        scrolltolower(){
          
        },
        // 返回键
        onClickLeft() {
            uni.redirectTo({
                url: '/pages/merchant/index'
            })
        },
        // 获取高度
        getHeights() {
            const query = uni.createSelectorQuery().in(this);
            query.select('.navBar').boundingClientRect(res => {
                if (res) {
                    this.navBarHeight = res.height; // 获取导航栏实际高度
                }
            }).exec();
            query.select('.searchStatistic').boundingClientRect(res => {
                if (res) {
                    this.stickyTop = res.top;
                }
            }).exec();
        },


        onCloseActions() {
            this.showActSheet = false
        },
        getStatusText(status) {
            const statusMap = {
                '1': '待入库',
                '2': '已入库',  //待出库
                '3': '已出库',
                '4': '异常',
                '5': '待退货入库',
                '6': '退货待出库',
                '7': '当前库存',
                '8': '滞留',
                '9': '退货已出库',
            }
            return statusMap[status] || '未知状态'
        },
        // 显示动作面板
        showMoreAction(packageInfo) {
            this.packageInfo = packageInfo
            console.log(packageInfo, 'packageInfo')
            this.showActSheet = true
        },

        onClose() {
            this.showActSheet = false
        },

        overlayActions() {
            this.showActSheet = false
        },

        // 隐藏带箭头的  显示页面底部的列表
        toInfo(item){
            console.log(item,'穿透')
            this.showExpressList = false
            this.currentHandlePhone = item.phone
            this.getSelfPickupDrillByPhone(item.phone)
            this.showBottomBtn = this.resultList.length>0 
        },

        // 清空
        clearData(){
            this.selectedRowKeys = []
            this.selectedRows = []
            this.checkAll = false
        },
        // 过滤selectedRows
        filterSelectedRows(list){
            if (this.selectedRowKeys.length > 0 && list.length > 0) {
                // 过滤掉 selectedRowKeys 中存在于 singleList 的元素
                this.selectedRowKeys = this.selectedRowKeys.filter(key => !list.includes(key));
                this.selectedRows = this.selectedRows.filter(row => !list.includes(row.orderId));
            }
        },

        onSearchInput(e) {
            this.searchValue = e.detail
        },
        onTabChange(e) {
            this.tabActive = e.detail
        },
        onSearch(e) {
            console.log(e, 'search')
            this.searchValue = e.detail
            if (this.searchValue.trim() == '') {
                wx.showToast({
                    title: '请输入搜索内容',
                    icon: 'none'
                })
                // this.searchview = false
                this.searchResult = []
                this.isShow = true
            } else {
                this.isShow = false
                console.log(this.searchValue, typeof (this.searchValue))
                this.showExpressList = this.current ==0 || this.current ==3
                this.getSelfPickupSearchInfo()
                this.showBottomBtn = this.resultList.length>0 && (this.current ==1 || this.current ==2)

            }
        },
        onChange(e) {
            console.log(e.detail, 'onchange')
            // this.searchValue = e.detail
            // this.isShow = true
            // if (this.searchValue.trim() === '') {
            //     // this.searchview = false
            //     this.searchResult = []
            //     return
            // }
            // console.log(this.searchValue, typeof (this.searchValue))

            // const searchResult = this.list.filter(item => {
            //     return item.orderNum.includes(this.message)
            // })

            // if (searchResult.length > 0) {
            //     this.searchview = true
            //     this.searchList = searchResult
            // } else {
            //     this.searchview = false
            //     this.searchList = []
            // }
        },

        onClick(event) {
            console.log('点击事件触发 搜索', event)
            console.log(this.searchValue)
            if (this.searchValue.trim() === '') {
                wx.showToast({
                    title: '请输入搜索内容',
                    icon: 'none'
                })
                this.isShow = true
            } else {
                this.isShow = false
            }
            this.showExpressList = this.current ==0 || this.current ==3
            this.getSelfPickupSearchInfo()
            this.showBottomBtn = this.resultList.length>0 && !this.showExpressList
            // const searchResult = this.list.filter(item => {
            //     return item.orderNum.includes(this.value)
            // })
            // if (searchResult.length > 0) {
            //     this.searchview = true
            //     this.searchList = searchResult
            //     // this.setData({
            //     //     searchview: true,
            //     //     searchList: searchResult
            //     // }, () => {
            //     //     // 在动态渲染完成后，滚动到搜索结果视图
            //     //     this.setData({
            //     //     scrollIntoView: 'searchResultView'
            //     //     });
            //     // });
            // } else {
            //     wx.showToast({
            //         title: '未找到相关商品',
            //         icon: 'none'
            //     })
            // }
        },
        // 点击确认按钮后的提示弹窗 中对应的文字
        getTipsStatusText(status) {
            const statusMap = {
                '1': '入库',
                '2': '出库',
                '4': '入库', // 异常状态下，显示入库
                '5': '退件入库',
                '6': '退件出库',
                '8':'出库' // 滞留状态下，显示出库

            }
            return statusMap[status] || '未知状态'
        },
        // 清空搜索框
        clearSearchData() {
            this.searchValue = ''
            this.expressList = []
            this.resultList = []
            this.showBottomBtn = false
            this.showExpressList = this.current ==0 || this.current ==3
        },
        // 搜索框取消按钮
        onCancel() { },

        // 切换搜索类型
        selectFilter(val,e,name){
            this.current=val
            if (val==1 || val==2) {
                this.showExpressList = false
            }else{
                this.showExpressList = true
            }
            this.searchValue = ''
            this.expressList=[]
            this.resultList=[]
            this.showBottomBtn = false
        },

        // 多选单选全选
        handleCheckboxChange({item, checked}) {
            console.log(item, 'i', checked, 'c')
            const index = this.selectedRowKeys.indexOf(item.orderId)
            console.log(index, 'indes')
            if (item.isChecked === true) {
                if (index === -1) {
                    this.selectedRowKeys.push(item.orderId)
                    this.selectedRows.push(item)
                }
                // this.selectedRowKeys.push(item.orderId)
                // this.selectedRows.push(item)
            } else {
                this.selectedRowKeys.splice(index, 1)
                this.selectedRows.splice(index, 1)
            }
            console.log(this.selectedRowKeys, 'selectedRowKeys')
            this.checkAll = this.selectedRowKeys.length === this.newResultList.length
            this.resultList.forEach(ele => {
                if (ele.orderId === item.orderId) {
                    ele.isChecked = checked
                }
            })
            this.newResultList.forEach(ele => {
                if (ele.orderId === item.orderId) {
                    ele.isChecked = checked
                }
            })
        },
        // 标记  选择框  文字
        handlechecked (item, checked) {
            console.log(item, checked, '单选----',this.newResultList)
            this.checkAll = this.checked.length === this.newResultList.length
            const index = this.selectedRowKeys.indexOf(item.orderId)

            if (checked === true) {
                this.selectedRowKeys.push(item.orderId)
                this.selectedRows.push(item)
            } else {
                console.log(index, 'indesR')
                this.selectedRowKeys.splice(index, 1)
                this.selectedRows.slice(index, 1)
            }
            this.resultList.forEach(ele => {
                if (ele.orderId === item.orderId) {
                    ele.isChecked = checked
                }
            })
            this.newResultList.forEach(ele => {
                if (ele.orderId === item.orderId) {
                    ele.isChecked = checked
                }
            })

        },
        // 全选后面的文字
        onChangeItem (type, item) {
            console.log(type, 'type', 'onChange')
            if (type === '多选') {
                this.checkAll = !this.checkAll
                console.log(this.checked)
                this.handleSelectAll(this.checkAll, !this.select)

            } else {
                if (item.status !== 2) {
                    return false;
                }
                item.status = !item.status;
                this.handleCheckLogic(item, item.status);
            }
        },
        // 处理全选
        handleSelectAll(checked, isManageMode) {
            const targetList = this.newResultList
            const allCheckedIds = targetList.map(item => item.orderId)
            targetList.forEach(item => { item.isChecked = checked })

            if (checked) {
                this.checked = allCheckedIds;
                this.selectedRows = JSON.parse(JSON.stringify(targetList));
            } else {
                this.checked = [];
                this.checkAll = false;
                this.selectedRows = [];
            }
            this.selectedRowKeys = this.checked;
        },

        // 处理全选
        handleCheckAll(val) {
            console.log(val, '全选按钮')
            const checkAll = val.detail
            const targetList = this.newResultList
            const allCheckedIds = targetList.map(item => item.orderId)
            targetList.forEach(item => { item.isChecked = checkAll })
            if (checkAll) {
                this.selectedRows = JSON.parse(JSON.stringify(targetList));
                this.checked = allCheckedIds
            } else {
                this.selectedRows = []
                this.checked = []
            }
            this.selectedRowKeys = this.checked
            console.log(this.resultList, 'resultList')
        },

        // 一键出库
        async allTakeOut(){
            // 如果正在提交，直接返回
            if (this.isSubmiting) {
                return;
            }
            this.isSubmiting = true;
            try {
                if (this.selectedRowKeys.length == 0) {
                    return false
                }
                await this.handleOutbound('multiple')
                console.log(this.selectedRowKeys, 'selectedRowKeys')
                console.log(this.selectedRows, 'selectedRows')
            } catch (error) {
                console.error('一键出库操作出错:', error);
            } finally {
                // 无论成功或失败，在操作完成后，经过一定时间（这里设置为 500 毫秒）将 isSubmiting 设为 false
                setTimeout(() => {
                    this.isSubmiting = false;
                }, 500);
            }
        },
        // 出入库单个包裹
        submitSinglePackage(item,status,handleType) {
            console.log(item, '单个包裹',status,handleType)
            const selectedList =[]
            selectedList.push(item.orderId)
            if(handleType=='single'){
                this.singleList = selectedList
                console.log(this.singleList,'singleList')
            }
            Dialog.confirm({
                // title: '标题',
                message: `确定${this.getTipsStatusText(item.status)}${item.orderId}?`,
            })
            .then(() => {
                if(item.status=='1' || item.status==4 || item.status == 5){
                   this.handleInbound(handleType,item.status)
                }else if(item.status=='2' || item.status==6 ||item.status==7 || item.status == 8){
                    this.handleOutbound(handleType)
                }
            })
            .catch(() => {
                this.singleList=[]
                console.log('cancel')
            });
        },
        
        // 取消出库
        cancelStockOut(info) {
            Dialog.confirm({
                message: `确定${info.orderId}取消出库吗?`,
            })
            .then(() => {
                console.log('confirm')
                this.cancelInOrOut(info)
            })
            .catch(() => {
                // on cancel
            });
        },
        // 取消入库
        // 弹窗取消
        onConfirmCancel(type,info) {
            console.log(type, '取消入库',info)
            this.cancelInOrOut(info)
        },

        // 取消出入库    2 已入库  4 出库  5 退货入库  6 退货出库 单独的按钮
        cancelInOrOut(info) {
            console.log(info, '取消出入库')
            const inOrOut = [2, 6].includes(info.status) ? 0 : 1;  //原来是245  应该是已经入库的
            const isReturn = [5, 6].includes(info.status)? 1 : 0;
            cancelSelfPickupApi({
              orderId: info.orderId,
              isReturn:isReturn, // 是否退货入库 0=不是 1=是
              inOrOut:inOrOut, // 入库 0=入库 1=出库
            }).then(res => {
                if (res.code === 200) {
                    Toast('取消成功')
                    // Toast({
                    //     message: `取消${this.getTipsStatusText(info.status)}${info.wayBillNo}`,
                    //     duration: 3000
                    // });
                    this.resultList=[]
                    if(this.current==1 || this.current==2){
                        this.getSelfPickupSearchInfo()
                    }else{
                        this.getSelfPickupDrillByPhone(this.currentHandlePhone)
                    }
                }
            })
        },
        // 取消退货入库
        cancelReturnStockIn(item) {
            Dialog.confirm({
                // title: '标题',
                message: `确定${item.orderId}取消退货入库吗?`,
            }).then(() => {
                this.cancelInOrOut(item)
            })
            .catch(() => {
                // on cancel
            });
        },

        // 入库 单个或者批量
       async handleInbound(type,status) {
            console.log(type, '出入库')
            let selectedCount = 0
            const list = this.singleList // 存储单个出入库时选中的包裹
            if(type=='multiple'){
              selectedCount = this.selectedRowKeys.length
            }
            handleInboundApi({
                orderIdList:type=='single'? this.singleList :this.selectedRowKeys,
                isReturn:status==6 || status==5 ? 1 :0 // 是否退货入库 0=不是 1=是
            }).then(res=>{
                console.log(res,'入库')
                if(res.code==200){
                    if(type=='single'){
                        Toast('已入库')
                        this.filterSelectedRows(list)
                        this.singleList=[]
                    }else{
                        Toast({
                            message: `批量入库${selectedCount}个商品`,
                            duration: 3000
                        });
                        // 使用 setTimeout 确保 Toast 显示后再执行 clearData
                        setTimeout(() => {
                            this.clearData()
                        }, 3000);
                    }
                    this.resultList=[]
                    console.log(this.current,'current',this.currentHandlePhone,'currentHandlePhone')
                    // this.pageNum=1
                    // this.loading = false
                    // this.finished = false
                    if(this.current==1 || this.current==2){
                        this.getSelfPickupSearchInfo()
                    }else{
                        this.getSelfPickupDrillByPhone(this.currentHandlePhone)
                    }
                    
                }
            })
        },
        // 出库
        async handleOutbound(type,status) {
            console.log(type, '出库',this.singleList)
            let selectedCount = 0
            const list = this.singleList // 存储单个出入库时选中的包裹
            if(type=='multiple'){
              selectedCount = this.selectedRowKeys.length
            }
            handleOutboundApi({
                orderIdList:type=='single'? this.singleList :this.selectedRowKeys,
                isReturn:status && (status==6 || status==5) ? 1 :0  // 是否退货入库 0=不是 1=是   //     TO_BE_RETURN_STORED(5, "待退货入库"),  //     RETURN_TO_BE_OUTBOUND(6, "退货待出库"),

            }).then(async res=>{
                console.log(res,'出库')
                if(res.code==200){
                    if(type=='single'){
                        Toast('已出库')
                        this.filterSelectedRows(list)
                        this.singleList=[]
                    }else{
                        Toast({
                            message: `批量出库${selectedCount}个商品`,
                            duration: 3000
                        });
                        this.clearData()
                    }
                    this.resultList=[]
                    console.log(this.current,'current','currentHandlePhone',this.currentHandlePhone)
                    // this.pageNum=1
                    // this.loading = false
                    // this.finished = false
                    // debugger
                    if(this.current==1 || this.current==2){
                        await this.getSelfPickupSearchInfo()
                        console.log(this.resultList,'resultList')
                        this.showBottomBtn = this.resultList.length>0
                    }else{
                        await this.getSelfPickupDrillByPhone(this.currentHandlePhone)
                        console.log(this.resultList,'resultList')
                        this.showBottomBtn = this.resultList.length>0
                    }
                }
            })
        },

        // 搜索按钮
        async getSelfPickupSearchInfo(){
            let data = {
                months: 3,
                queryType:this.current==0?1:this.current==1?3:this.current==2?2:4,
            };
            switch (this.current) {
                case 0:
                    data.phone = this.searchValue;
                    break;
                case 1:
                    data.waybillNo = this.searchValue;
                    break;
                case 2:
                    data.pickupCode = this.searchValue;
                break;
                case 3:
                    data.name = this.searchValue;
                    break;
                default:
                    break;
            }
            getSelfPickupSearchApi(data).then(res=>{
                console.log(res,'getSelfPickupSearchApi')
                if(res.code==200){
                    if(this.current==0 || this.current==3){
                        this.expressList = res.data?.packageStatVOList || []
                        this.allNonOutboundCount = res.data?.allNonOutboundCount || 0
                        // debugger
                        this.nameCount = res.data?.nameCount || 0
                        this.phoneCount = res.data?.phoneCount || 0
                    }
                    this.total = res.data.total;
                    if(this.current==1 || this.current==2){
                        this.resultList=res.data?.packageStatVOList || []
                        this.resultList.forEach(ele => {
                            this.$set(ele, 'isShow', false)
                            this.$set(ele, 'isChecked', false)
                            if(ele.status){
                                ele.statusText = this.getStatusText(ele.status)
                            }
                        });
                        this.showBottomBtn = this.resultList.length>0
                    }
                    this.$forceUpdate(); // 强制组件重渲染
                   
                }
            })
        },
        // 点击手机号  显示该手机号下对应的所有包裹列表
        async getSelfPickupDrillByPhone(phone){
            getSelfPickupDrillByPhoneApi({
              phone:phone
            }).then(res=>{
                console.log(res,'getSelfPickupDrillByPhoneApi')
                if(res.code==200){
                    this.resultList=res?.data || []
                    this.resultList.forEach(ele => {
                        this.$set(ele, 'isShow', false)
                        this.$set(ele, 'isChecked', false)
                        if(ele.status){
                            ele.statusText = this.getStatusText(ele.status)
                        }
                    });
                    this.showBottomBtn = this.resultList.length>0
                }
            })
        }
    },

}
</script>
<style lang="scss" scoped>
::v-deep .navBar .van-icon {
    color: #242629 !important;
}
.content {
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    box-sizing: border-box;
    padding-bottom: calc(0rpx + env(safe-area-inset-bottom));
}

.page{
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    box-sizing: border-box;
}
.scroll-content {
    flex: 1;
    height: 1px;
}
.pageTitle{
    padding: 0 48rpx;
    font-weight: 500;
    font-size: 56rpx;
    text-align: left;
    color: #333;

    span{
        font-weight: 400;
        font-size: 24rpx;
        text-align: left;
        color: #999;
        margin-left: 32rpx;
    }
}
.search-container {
    margin-left: 48rpx;
    margin-right: 48rpx;
    margin-top: 32rpx;
    // background-color: #f9f9f9; /* 背景颜色 */
    border-radius: 32rpx;
    background: #fff;

}
.sticky {
    width: 100%;
    position: fixed;
    top: 0;
    z-index: 999;
    background: #efefef;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.search-style {
    background-color: transparent;
    /* 搜索框背景透明 */
    border-radius: 20px;
    /* 圆角边框 */
    padding: 0 40px 0 10px;
    /* 内边距，为"搜索"二字留出空间 */
}
// 综合  销量  价格按钮
.tabsBox {
    padding: 24rpx 48rpx 0 48rpx;
    margin-bottom: 32rpx;
    display: flex;

    .filter_option {
        font-size: 24rpx;
        text-align: center;
        height: 48rpx;
        line-height: 48rpx;
        border-radius: 8rpx;
        color: #333333;
        background: #f4f4f4;
        margin-right: 10px;
        // padding-left: 9px;
        // padding-right: 9px;
        width: 112rpx;
    }

    .filter_option_selected:last-child {
        margin-right: 0px;
    }

    .filter_option_selected {
        border-radius: 8rpx;
        background: rgb(255, 98, 3, 0.1);
        color: #ff6203;
    }
}

// 搜索结果的数据统计
.searchStatistic{
    height: 64rpx;
    background: #efefef;
    color: #333333;
    font-size: 24rpx;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 64rpx;
    padding-left: 48rpx;
    padding-right: 48rpx;

    span{
        color: #FF6203;
    }
    // &[style*="display: none"] {
    //     display: none !important;
    // }
    // &[style*="display: block"] {
    //     display: block !important;
    // }
}

// 搜索结果列表
.expressListBox{
    padding-bottom: 144rpx;
    margin-bottom: 32rpx;

    .expressList{
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding:34rpx 0rpx;
        border-bottom: 1rpx solid #e6e6e6;

        .expressList_left{
            display: flex;
            align-items: center;
            font-size: 24rpx;
            text-align: left;
            color: #333;
            
        }
        .expressList_right{
            display: flex;
            align-items: center;
            font-size: 24rpx;
            text-align: left;
            color: #333;

            .num{
                color: #ff6203;
                margin-left: 8rpx;
                margin-right: 16rpx;
            }
        }
    }
}

::v-deep .expressList_right .van-icon{
    color: #666666;
    font-size: 24rpx;
}

// 搜索框的输入框
::v-deep .van-search {
    padding: 0px;
    background: transparent;
    border-radius: 32rpx;
    border: 1rpx solid #ff6202;
    height: 64rpx;
}

::v-deep .van-search--withaction {
    background: transparent;

}

::v-deep .van-search__content {
    background-color: transparent;
    // padding-left: 0px !important;
}

::v-deep .van-search__content--round {}

::v-deep .van-search__action {
    border-radius: 28rpx;
    background: #ff6203;
    font-size: 28rpx;
    color: #ffffff !important;
    height: 56rpx;
    line-height:56rpx;
    margin-right: 10px;
    width: 120rpx;
    text-align: center;
}

::v-deep .van-icon-search {
    color: #888888;
}

.checked-img {
    height: 16px;
    width: 16px;
}
::v-deep .bar-class, .van-submit-bar__bar{
  display: flex;
  justify-content: space-between !important;
  border-top: 1px solid #f9f9f9 !important;
  // padding-top: 20px !important;
}
::v-deep .van-submit-bar__tip {
    color: #FF6203 !important;
    background-color:#FFF9F7 !important;
    padding-left: 24px !important;
    padding-right: 24px !important;
    line-height: 35px !important;

}
::v-deep .van-button--warning {
    background-color: #FF6203;
}
::v-deep .van-empty__image {
    width: 300rpx;
    height: 300rpx;
}
// 动作面版
.van-action-sheet__header {
    font-size: var(--action-sheet-header-font-size,16px);
    font-weight: var(--font-weight-bold,500);
    line-height: var(--action-sheet-header-height,48px);
    text-align: left;
    padding: 0 48rpx !important;
}
.ml40{
    margin-left: 40rpx;
}
// 定义新的类
::v-deep .is-submiting .van-submit-bar__button {
    // 可以根据需求修改样式，例如禁用状态的背景色
    background-color: #cccccc; 
    // 禁用状态的文字颜色
    color: #999999; 
    // 禁用鼠标指针样式
    cursor: not-allowed; 
}
</style>